# -*- coding: utf-8 -*-
# @Time    : 2021/11/9 22:32
# @Author  : super

import pymysql

if __name__ == '__main__':
	# 创建链接
	conn = pymysql.connect(host = 'localhost', port = 3306, user = 'root', password = '123456', database = 'world',
	                       charset = 'utf8')

	# 创建游标对象
	cursor = conn.cursor()

	# 准备sql语句
	sql = "SELECT * FROM city WHERE id = %s AND `name` = %s;"

	# 执行带参sql语句
	row_number = cursor.execute(sql, [1, "Kabul"])
	print(row_number)

	# 打印查询sql
	for item in cursor.fetchall():
		print(item)

	# 关闭游标对象
	cursor.close()

	# 关闭数据库链接
	cursor.close()